import Vue from 'vue'
import Router, { RouteConfig } from 'vue-router'
import { risksystemRouters } from './risksystem'

Vue.use(Router)
// 配置说明
// 所有的详情页，只要是在本地配置的必须配置activeMenu属性，path对应对应高亮系统在左侧显示的父级菜单
/* meta: {
  title: 'title'               面包屑和导航栏显示导航字体
  icon: 'svg-name'             显示icon
  hidden: true                 if true, this route will not show in the sidebar (default is false)
  alwaysShow: true             if true, will always show the root menu (default is false)
                               if false, hide the root menu when has less or equal than one children route
  noCache: true                if true, the page will not be cached (default is false)
  affix: true                  if true, the tag will affix in the tags-view
  activeMenu: '/example/list'  详见navbar sidebar手动高亮函数
  showTooltip                   如果为true，显示tooltip，默认为false
  showTooltipContent            显示tooltip文字，前提是showTooltip为true
  showScreenFull                显示fullScreen控件
} */

// 子应用独立处理自己的404
export const constantRoutes: RouteConfig[] = [
  {
    path: '/404',
    component: () => import('@/views/error-page/404.vue'),
    meta: {
      title: '404',
      activeMenu: '/risksystem'
    }
  }
]

const routers = [...risksystemRouters, ...constantRoutes]

const createRouter = () =>
  new Router({
    mode: 'history',
    base: process.env.BASE_URL,
    routes: routers
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  ;(router as any).matcher = (newRouter as any).matcher // reset router
}
export default router
